package org.sump.ui.gwt.forms.client;

import org.sump.ui.gwt.client.SUMPWidget;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;
import com.gwtent.client.reflection.ClassType;
import com.gwtent.client.reflection.Method;
import com.gwtent.client.reflection.TypeOracle;
import com.gwtent.client.template.HTMLWidget;
import com.gwtent.client.template.UIBind;
import com.gwtent.client.uibinder.GWTUIBinderRegister;

public class FormsEntryPoint implements EntryPoint {

	protected Person person;
	
	@HTMLWidget
	@UIBind(path = "person.firstName")	
	protected TextBox txtFirstName = new TextBox();

	@HTMLWidget
	@UIBind(path = "person.lastName")	
	protected TextBox txtLastName = new TextBox();
	
	@HTMLWidget
	@UIBind(path = "person.firstName")	
	protected TextBox txtFirstName2 = new TextBox();

	@HTMLWidget
	@UIBind(path = "person.lastName")	
	protected TextBox txtLastName2 = new TextBox();
	
	public void onModuleLoad() {
		GWTUIBinderRegister.register();
		person = GWT.create(Person.class);

		person.setFirstName("John");
		person.setLastName("Smith");
		
		RootPanel rp = RootPanel.get();
		rp.add(new SUMPWidget());
		TextArea ta;
		rp.add(ta = new TextArea());

		Person p = (Person) GWT.create(Person.class);
		ClassType classType = TypeOracle.Instance.getClassType(Person.class);
		Method[] methods = classType.getMethods();
		ta.setWidth("800px");
		ta.setHeight("400px");
		StringBuffer sb = new StringBuffer();
		for (Method method : methods) {
			sb.append(method.getName() + "\n");

		}
		ta.setText(sb.toString());

		p.setFirstName("John");
		p.setLastName("Brown");
		p.getFirstName();
		p.getLastName();
		
		Button b = new Button();
		b.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent arg0) {
				System.out.println(person);
			}
			
		});

		rp.add(txtFirstName);
		rp.add(txtLastName);
		rp.add(b);
		rp.add(txtFirstName2);
		rp.add(txtLastName2);

	}

	public Person getPerson() {
		return person;
	}

}
